package com.wanmait.shoppingsys.controller.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanmait.shoppingsys.dao.CityDAO;
import com.wanmait.shoppingsys.util.Pager;
import com.wanmait.shoppingsys.vo.City;

@WebServlet("/CityController")
public class CityController extends HttpServlet{
	
	private CityDAO cityDAO = CityDAO.getDAO();
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String action = request.getParameter("action");
		if(action==null) return;
		switch(action)
		{
		case "findbycity":
			this.findbycity(request, response);
			break;
		case "citybyprice":
			this.citybyprice(request, response);
			break;
		case "citybylike":
			this.citybylike(request, response);
			break;
		}
	}
	protected void findbycity(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		 Pager pager = Pager.initc(request); 
		 cityDAO.findByCity(pager);
		 request.getRequestDispatcher("/specialty/serachlist.jsp").forward(request, response);
		
	}
	protected void citybyprice(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		 Pager pager = Pager.initc(request); 
		 cityDAO.cityByPrice(pager);
		 request.getRequestDispatcher("/specialty/serachlist.jsp").forward(request, response);
		
	}
	protected void citybylike(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		 Pager pager = Pager.initc(request); 
		 cityDAO.cityByLike(pager);
		 request.getRequestDispatcher("/specialty/serachlist.jsp").forward(request, response);
		
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
